package cn.cas.mango.dto.param.neo4j;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Property;
import org.springframework.data.neo4j.core.schema.Relationship;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Data
@Node
@NoArgsConstructor
@AllArgsConstructor
public class NodeEntity {
  @Id
  private String id;
  private String title;
  private String content;
  private LocalDate date;
  private Object domain;
  private Object source;
  private List<String> area;

  @Relationship(type="-")
  private List<RelationshipEntity> n = new ArrayList<>();
  @Property(value = "clusterId")
  private String clusterId;

  public void addRelationShip(NodeEntity node, double score) {
    n.add(new RelationshipEntity(node, score));
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof NodeEntity)) return false;
    NodeEntity node = (NodeEntity) o;
    return Objects.equals(getId(), node.getId());
  }

  @Override
  public int hashCode() {
    return Objects.hash(getId());
  }

  public void addRelationShip(List<NodeEntity> nodes, List<Double> scores) {
    for (int i = 0; i < nodes.size(); i++) {
      addRelationShip(nodes.get(i), scores.get(i));
    }
  }
}
